package com.driving.single.frontend.school.controller;

import com.driving.single.common.entity.DrivingResult;
import com.driving.single.frontend.school.service.FrontendSchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/frontend/school", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class FrontendSchoolController {
    @Autowired
    private FrontendSchoolService frontendSchoolService;

    /**
     * 实现根据主键查询驾校接口
     *
     * @param id 主键
     */
    @GetMapping("/selectSchoolById/{id}")
    public DrivingResult selectSchoolById(@PathVariable Long id) {
        try {
            return this.frontendSchoolService.selectSchoolById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DrivingResult.error("error");
    }

    /**
     * 实现根据驾校ID   查询驾校班级及费用   接口
     *
     * @param school_id 主键
     */
    @GetMapping("/selectSchoolClassesBySid/{school_id}")
    public DrivingResult selectSchoolClassesBySid(@PathVariable Long school_id) {
        try {
            return this.frontendSchoolService.selectSchoolClassesBySid(school_id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DrivingResult.error("error");
    }

    /**
     * 实现根据驾校ID  查询驾校服务   接口
     *
     * @param school_id 主键
     */
    @GetMapping("/selectSchoolServiceBySid/{school_id}")
    public DrivingResult selectSchoolServiceBySid(@PathVariable Long school_id) {
        try {
            return this.frontendSchoolService.selectSchoolServiceBySid(school_id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DrivingResult.error("error");
    }

    /**
     * 实现找驾校页面驾校查询 接口
     *
     * @param page        当前页
     * @param rows        页显示数
     * @param area        查询条件：区域(学校名称)
     * @param licenseType 查询条件：驾照类型
     * @param minPrice    查询条件：最小价格
     * @param maxPrice    查询条件：最大价格
     */
    @RequestMapping("/selectSchoolsWithPage/{page}")
    public DrivingResult selectTbSchoolListByConditionWithPage(@PathVariable Integer page,
                                                               @RequestParam(defaultValue = "4") Integer rows,
                                                               String area,
                                                               String licenseType,
                                                               Integer minPrice,
                                                               Integer maxPrice) {
        try {
            return this.frontendSchoolService.selectTbSchoolListByConditionWithPage(page, rows, area, licenseType,
                    minPrice,
                    maxPrice);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DrivingResult.error("error");
    }

    /**
     * 实现根据驾校ID   查询驾校评论   接口
     * @param school_id 驾校主键
     * @param page      当前页
     * @param rows      页显示数
     */
    @RequestMapping("/selectSchoolCommentBySid/{school_id}/{page}")
    public DrivingResult selectSchoolCommentBySidWithPage(@PathVariable Long school_id,
                                                          @PathVariable Integer page,
                                                          @RequestParam(defaultValue = "4") Integer rows) {
        try {
            return this.frontendSchoolService.selectSchoolCommentBySidWithPage(school_id, page, rows);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DrivingResult.error("error");
    }

    /**
     * 实现根据驾校ID   分页查询驾校相册   接口
     * @param school_id 驾校主键
     * @param photoType 相册图片类型,1:训练场地,2:训练车,3:周边环境
     * @param page      当前页
     * @param rows      页显示数
     */
    @RequestMapping("/selectSchoolPhotoAlbumBySid/{school_id}/{page}")
    public DrivingResult selectSchoolPhotoAlbumBySidWithPage(@PathVariable Long school_id,
                                                          @RequestParam(required = false) Integer photoType,
                                                          @PathVariable Integer page,
                                                          @RequestParam(defaultValue = "8") Integer rows) {
        try {
            return this.frontendSchoolService.selectSchoolPhotoAlbumBySidWithPage(school_id,photoType, page, rows);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DrivingResult.error("error");
    }
}
